/***************************************************************************
 创建者: 华磊
 开始时间: 2019.4.26
 copyright: (C) 华友高科
 修改说明: (每次有修改就添加一条，带有 修改人，修改时间，修改描述)
 example (1) hualei 2017.5.8 类的具体实现代码编写
 ***************************************************************************/
#include "trackstartlogic.h"

#include "mccontrollerthread.h"
#include "programengine.h"

TrackStartLogic::TrackStartLogic(int robotIdIn, ProgramEngine *programEngineIn, McControllerThread *programMcControllerIn)
{
    robotId=robotIdIn;
    programEngine=programEngineIn;
    programMcController=programMcControllerIn;
}

E_PROGRAM_LOOP_RESULT TrackStartLogic::startTrackStart(int programNumIn, const TrackStartInstruction &instructionIn, int lineIndex)
{
    Q_UNUSED(lineIndex);

    if(0>programMcController->mcControllerInterpreter->beltTrackStart(instructionIn.beltIndex))
    {
        return E_PROGRAM_LOOP_RESULT_ERROR;
    }

    programEngine->calculateNextLineToRun(programNumIn);
    return programEngine->isTheLastInstruction(programNumIn);
}

E_PROGRAM_LOOP_RESULT TrackStartLogic::startTrackEnd(int programNumIn, const TrackEndInstruction &instructionIn, int lineIndex)
{
    Q_UNUSED(lineIndex);

    if(0>programMcController->mcControllerInterpreter->beltTrackEnd(instructionIn.beltIndex))
    {
        return E_PROGRAM_LOOP_RESULT_ERROR;
    }

    programEngine->calculateNextLineToRun(programNumIn);
    return programEngine->isTheLastInstruction(programNumIn);
}

E_PROGRAM_LOOP_RESULT TrackStartLogic::startTrackGetData(int programNumIn, const TrackGetDataInstruction &instructionIn, int lineIndex)
{
    Q_UNUSED(lineIndex);

    if(0>programMcController->mcControllerInterpreter->getTrackData(instructionIn.beltIndex))
    {
        return E_PROGRAM_LOOP_RESULT_ERROR;
    }

    programEngine->calculateNextLineToRun(programNumIn);
    return programEngine->isTheLastInstruction(programNumIn);
}
